package com.ruoyi.web.controller.supervise;

import java.text.SimpleDateFormat;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.supervise.domain.ProsAccessories;
import com.ruoyi.supervise.service.IProsAccessoriesService;

/**
 * 附件Controller
 * 
 * @author ruoyi
 * @date 2019-10-12
 */
@Controller
@RequestMapping("/supervise/Accessories")
public class ProsAccessoriesController extends BaseController
{
    private String prefix = "supervise/Accessories";

    @Autowired
    private IProsAccessoriesService prosAccessoriesService;

    @RequiresPermissions("supervise:Accessories:view")
    @GetMapping()
    public String Accessories()
    {
        return prefix + "/Accessories";
    }

    /**
     * 查询附件列表
     */
    @RequiresPermissions("supervise:Accessories:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProsAccessories prosAccessories)
    {
        startPage();
        List<ProsAccessories> list = prosAccessoriesService.selectProsAccessoriesList(prosAccessories);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @RequiresPermissions("supervise:Accessories:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProsAccessories prosAccessories)
    {
        List<ProsAccessories> list = prosAccessoriesService.selectProsAccessoriesList(prosAccessories);
        ExcelUtil<ProsAccessories> util = new ExcelUtil<ProsAccessories>(ProsAccessories.class);
        return util.exportExcel(list, "Accessories");
    }

    /**
     * 新增附件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存附件
     */
    @RequiresPermissions("supervise:Accessories:add")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProsAccessories prosAccessories)
    {
        return toAjax(prosAccessoriesService.insertProsAccessories(prosAccessories));
    }

    /**
     * 修改附件
     */
    @GetMapping("/edit/{guid}")
    public String edit(@PathVariable("guid") String guid, ModelMap mmap)
    {
        ProsAccessories prosAccessories = prosAccessoriesService.selectProsAccessoriesById(guid);
        mmap.put("prosAccessories", prosAccessories);
        return prefix + "/edit";
    }

    /**
     * 修改保存附件
     */
    @RequiresPermissions("supervise:Accessories:edit")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProsAccessories prosAccessories)
    {
        return toAjax(prosAccessoriesService.updateProsAccessories(prosAccessories));
    }
    
    /**
     * 附件详情
     */
    @GetMapping("/detail/{guid}")
    public String detail(@PathVariable("guid") String guid, ModelMap mmap)
    {
        ProsAccessories prosAccessories = prosAccessoriesService.selectProsAccessoriesById(guid);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String newCreatedate=sdf.format(prosAccessories.getCreatedate());
        String newCompletedtime=sdf.format(prosAccessories.getCompletedtime());
        mmap.put("prosAccessories", prosAccessories);
        mmap.put("newCreatedate", newCreatedate);
        mmap.put("newCompletedtime", newCompletedtime);
        return prefix + "/detail";
    }

    /**
     * 删除附件
     */
    @RequiresPermissions("supervise:Accessories:remove")
    @Log(title = "附件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(prosAccessoriesService.deleteProsAccessoriesByIds(ids));
    }
}
